import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormat {
    public static void main(String[] args) throws JsonProcessingException {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");

        System.out.println(date);
        System.out.println(simpleDateFormat.format(date));

        //Mon Mar 08 09:43:24 CST 2021
        //20210308

        ObjectMapper objectMapper = new ObjectMapper();
        String string = objectMapper.writeValueAsString(date);
        Date date1 = objectMapper.readValue(string,Date.class);
        System.out.println(string);
        System.out.println(date1);

        Long aLong = Long.valueOf(simpleDateFormat.format(date));
        System.out.println(aLong);

    }
}
